package admin

import (
	"github.com/gin-gonic/gin"
	"go-project/dto/requrest"
	"go-project/pkg/utils"
	"go-project/service"
	"log"
	"net/http"
)

type OfficialAccountController struct {
}

func (OfficialAccountController) Setting(c *gin.Context) {
	if c.Request.Method == "POST" {
		request := &requrest.OfficialAccountSettingRequest{}
		err := request.BindAndValidate(c)
		if err != nil {
			return
		}
		err = (&service.OfficialAccountSetting{}).Set(request)
		if err != nil {
			utils.Error(c, utils.ERROR, err.Error(), http.StatusOK)
			return
		}
		utils.Success(c, gin.H{}, http.StatusCreated)
		return
	}
	var officialAccountSetting = new(service.OfficialAccountSetting)
	err := officialAccountSetting.Get()
	if err != nil {
		c.HTML(http.StatusBadGateway, "admin.error", gin.H{
			"error": err.Error(),
		})
		return
	}
	log.Println(officialAccountSetting, "officialAccountSetting")
	c.HTML(http.StatusOK, "official-account.setting", gin.H{
		"setting": officialAccountSetting,
	})

}

func (OfficialAccountController) Menus(c *gin.Context) {
	c.HTML(http.StatusOK, "official-account.menus", nil)
}
